No. Running a String
object's method does not change that object,
but creates a new String
object.
It seems a little odd that an object can create another object. This is not how real-world objects usually behave. Bricks do not create other bricks. Cars do not create other cars. But software objects often create new software objects.
Software objects are created:
There is no difference between objects created one way or the other.
The substring()
method of a String
object
creates a new object by asking the Java virtual computer to create a new object.
The virtual computer creates the new object in the usual way by following
the instructions contained in the class.
Do you imagine that there are other String
methods that create
new String
objects?